package com.ebring.shareEducation.controller;

import com.ebring.shareEducation.bean.Role;
import com.ebring.shareEducation.bean.SysparamInfo;
import com.ebring.shareEducation.bean.Traderecords;
import com.ebring.shareEducation.service.SystemParamService;
import com.ebring.shareEducation.service.TraderecordsService;
import com.ebring.shareEducation.utils.RspMsg;
import com.ebring.shareEducation.utils.UuidUtils;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://wangliang.vipgz1.idcfengye.com", maxAge = 3600)
@Api(value = "系统参数管理" ,tags = {"系统参数管理接口"})
public class SysparaInfoController {

    @Autowired
    private SystemParamService systemParamService;


    /**
     * 根据参数ID查找参数
     *
     * @param id 订单ID
     * @return
     */
    @GetMapping("/syspara/selectById")
    @ApiOperation(value="根据参数ID查找参数", notes="根据参数ID查找参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "id", value = "参数id", required = true, dataType = "String"),
    })
    public RspMsg<SysparamInfo> selectSysparaById(String id) {
        return systemParamService.selectsysparaById(id);
    }

    /**
     * 查找所有参数
     *
     * @param
     * @return
     */
    @GetMapping("/syspara/selectsyspara")
    @ApiOperation(value="查找所有参数", notes="查找所有参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "总页数", required = true, dataType = "Integer"),
    })
    public RspMsg<SysparamInfo> selectSysparafind(Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        return systemParamService.selectsysparafind();
    }








    /**
     * 参数管理模块模糊时查询

     * @param sysparamInfo
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/syspara/findSyspara")
    @ApiOperation(value="参数管理模块模糊时查询", notes="参数管理模块模糊时查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "SysparamInfo", value = "系统参数对象", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "总页数", required = true, dataType = "Integer"),
    })
    public RspMsg<List<SysparamInfo>> findSyspara(SysparamInfo sysparamInfo, Integer pageNum, Integer pageSize) {

        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        return systemParamService.findsyspara(sysparamInfo);
    }


    /**
     * 新增参数
     */
    @PostMapping("/syspara/insert")
    @ApiOperation(value="新增参数", notes="新增参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "参数名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "参数类型", required = true, dataType = "String"),
            @ApiImplicitParam(name = "srcParaId", value = "描述", required = true, dataType = "String"),


    })
    public RspMsg<SysparamInfo> insertsys(String name, String type,String srcParaId) {
        SysparamInfo sysparamInfo = new SysparamInfo();
        sysparamInfo.setParaId(UuidUtils.getNumberId(4));
        sysparamInfo.setParaType(type);
        sysparamInfo.setParaName(name);
        sysparamInfo.setSrcParaId(srcParaId);

        return systemParamService.insertsyspara(sysparamInfo);

    }

    /**
     * 修改参数
     */
    @PostMapping("/syspara/update")
    @ApiOperation(value="修改参数", notes="修改参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "SysparamInfo", value = "角色对象", required = true, dataType = "SysparamInfo"),
    })
    public RspMsg<SysparamInfo> updateRole(SysparamInfo sysparamInfo) {
        return systemParamService.updatesyspara(sysparamInfo);
    }

}
